package cn.stylefeng.guns.modular.gui.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.gui.entity.Yue;
import cn.stylefeng.guns.modular.gui.mapper.YueMapper;
import cn.stylefeng.guns.modular.gui.model.params.YueParam;
import cn.stylefeng.guns.modular.gui.model.result.YueResult;
import  cn.stylefeng.guns.modular.gui.service.YueService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 月份管理 服务实现类
 * </p>
 *
 * @author Dong
 * @since 2023-06-09
 */
@Service
public class YueServiceImpl extends ServiceImpl<YueMapper, Yue> implements YueService {

    @Override
    public void add(YueParam param){
        Yue entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(YueParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(YueParam param){
        Yue oldEntity = getOldEntity(param);
        Yue newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public YueResult findBySpec(YueParam param){
        return null;
    }

    @Override
    public List<YueResult> findListBySpec(YueParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(YueParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(YueParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private Yue getOldEntity(YueParam param) {
        return this.getById(getKey(param));
    }

    private Yue getEntity(YueParam param) {
        Yue entity = new Yue();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
